package com.travel.controller.open;

import com.travel.model.dto.comment.RatingStats;
import com.travel.model.dto.common.ApiResponse;
import com.travel.model.dto.service.ServiceDTO;
import com.travel.model.entity.content.Comment;
import com.travel.service.Service.TravelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//公开服务接口 , 获取所有服务, 获取服务详情, 获取服务评论, 获取服务评分统计
@Tag(name = "公开服务", description = "公开服务管理接口")
@RestController
@RequestMapping("/api/public/services")
@RequiredArgsConstructor
public class PublicServiceController {
    private final TravelService travelService;

    @Operation(summary = "获取公开服务列表")
    @GetMapping("/list")
    public ApiResponse<List<ServiceDTO>> getPublicServices() {
        return ApiResponse.success("获取成功", travelService.getPublicServices());
    }

    @Operation(summary = "获取服务详情")
    @GetMapping("/{id}")
    public ApiResponse<ServiceDTO> getServiceDetail(
            @Parameter(description = "服务ID", required = true) 
            @PathVariable Long id) {
        return ApiResponse.success("获取成功", travelService.getServiceDetail(id));
    }

    @Operation(summary = "获取服务列表", description = "获取所有旅游服务，支持城市和类型筛选")
    @GetMapping
    public ApiResponse<Page<ServiceDTO>> getAllServices(
            @Parameter(description = "城市筛选") @RequestParam(required = false) String city,
            @Parameter(description = "服务类型筛选") @RequestParam(required = false) String type,
            Pageable pageable) {
        return ApiResponse.success("获取成功", 
            travelService.getServices(city, type, pageable));
    }

    @Operation(summary = "获取服务评论", description = "获取指定服务的所有评论")
    @GetMapping("/{serviceId}/comments")
    public ApiResponse<List<Comment>> getComments(
            @Parameter(description = "服务ID") @PathVariable Long serviceId) {
        return ApiResponse.success("获取成功", 
            travelService.getComments(serviceId));
    }

    @Operation(summary = "获取服务评分统计")
    @GetMapping("/{serviceId}/rating")
    public ApiResponse<RatingStats> getServiceRating(
        @Parameter(description = "服务ID") @PathVariable Long serviceId) {
        return ApiResponse.success("获取成功", travelService.getServiceRating(serviceId));
    }
} 